package main

import (
	"context"
	"fmt"
	"google.golang.org/grpc"
	"grpc/grpc_test_matedata/proto"
	"net"
)

type Server struct {
}

func (s Server) SayHello(ctx context.Context, request *proto.HelloRequest) (*proto.HelloReply, error) {
	return &proto.HelloReply{
		Message: fmt.Sprintf("姓名:%s 性别%v",
			request.Name, request.G,
		),
	}, nil
}

func main() {
	g := grpc.NewServer()
	proto.RegisterGreeterServer(g, &Server{})
	listen, err := net.Listen("tcp", ":8088")
	if err != nil {
		panic("net.Listen(\"tcp\", \":8088\")" + err.Error())
	}

	err = g.Serve(listen)
	if err != nil {
		panic("g.Serve(listen)" + err.Error())
	}
}
